package logic

import (
	"context"
	"doctor-medicine-system/goods/goods"
	"doctor-medicine-system/goods/internal/svc"
	"doctor-medicine-system/model/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *goods.UpdateRequest) (*goods.UpdateResponse, error) {
	// todo: add your logic here and delete this line
	data := mysql.Goods{
		Name:   in.Name,
		Size:   in.Size,
		Form:   in.Form,
		Eat:    in.Eat,
		Use:    in.Use,
		Moment: in.Moment,
	}

	if err := data.UpdateGoods(mysql.DB, in.GoodId); err != nil {
		return nil, err
	}
	return &goods.UpdateResponse{
		GoodId: in.GoodId,
	}, nil
}
